package com.wondream.myframework.app.mybatis;

import com.wondream.myframework.app.dao.LitemallUserMapper;
import com.wondream.myframework.app.domain.LitemallUser;
import com.wondream.myframework.app.common.util.JacksonUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class MybatisDemo1 {
    public static void main(String[] args) throws Exception {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis/mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        LitemallUserMapper userMapper = sqlSession.getMapper(LitemallUserMapper.class);
        LitemallUser litemallUser = userMapper.selectByPrimaryKey(1);
        System.out.println(JacksonUtil.toJson(litemallUser));
    }
}
